/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elaborate.tag_analysis.client.actions;

import elaborate.tag_analysis.client.actions.cossim.CosineSimilarityCalc;
import elaborate.tag_analysis.client.actions.ui.MultipleFileSelectionDialog;
import elaborate.tag_analysis.client.actions.ui.multiplefileselector.MultipleFileSelectionConfEntry;
import elaborate.task.Task;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFileChooser;

/**
 *
 * @author lendle
 */
public class GenerateCossimCSVActionHandler extends BaseActionHandler {
    @Override
    protected void asyncHandleAction(ActionEvent event) {
        try {
            List<MultipleFileSelectionConfEntry> entries=new ArrayList<MultipleFileSelectionConfEntry>();
            
            MultipleFileSelectionConfEntry vectorFileEntry=new MultipleFileSelectionConfEntry();
            vectorFileEntry.setId("vector");
            vectorFileEntry.setDisplayName("Select Vector File");
            entries.add(vectorFileEntry);
            
            MultipleFileSelectionConfEntry csvFileEntry=new MultipleFileSelectionConfEntry();
            csvFileEntry.setId("csv");
            csvFileEntry.setDisplayName("Select Output CSV File");
            csvFileEntry.setSave(true);
            entries.add(csvFileEntry);
            
            final MultipleFileSelectionDialog dlg=new MultipleFileSelectionDialog((Frame)context.getMainFrame(), true);
            dlg.getFileSelector().setMultipleFileSelectionConfEntries(entries);
            dlg.setLocationRelativeTo(context.getMainFrame());
            dlg.setVisible(true);
            
            if(dlg.isOk()){
                context.executeTask(new Task(){

                    @Override
                    public Object run() throws Exception {
                        CosineSimilarityCalc calc=new CosineSimilarityCalc();
                        calc.calculate(dlg.getFileSelector().getSelectedFile("vector"), dlg.getFileSelector().getSelectedFile("csv"));
                        return null;
                    }
                });
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
